package mianshi;

import niuke.TreeNode;

/**
 * description:
 * author:张腾
 * date:2021-07-21
 */
public class _04_02 {
    public TreeNode sortedArrayToBST(int[] nums) {
        if(nums.length==0 || nums==null) return null;
        return toTree(nums,0,nums.length-1);
    }

    public TreeNode toTree(int[] nums,int l,int r){
        if(l>r) return null;
        int mid = l+(r-l)/2;
        TreeNode node = new TreeNode(nums[mid]);
        node.left = toTree(nums,l,mid-1);
        node.right = toTree(nums,mid+1,r);

        return node;
    }
}
